package java_thinking.unit_18_IO._18_8;

import java.io.*;

/**
 * @Desc:   标准I/O重定向，重定向操纵的是字节流不是字符流
 * @author: cww
 * @DateTime: 2019-05-16 22:08
 */

public class Redirecting {
    static String file = "src/maindemo/java/java_thinking/unit_18_IO/_18_8/Redirecting.java";
    public static void main(String[] args) throws IOException {
        PrintStream console = System.out;
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
        PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("src/maindemo/java/java_thinking/unit_18_IO/_18_8/Redirecting.txt")));
        //将标准输入附接到文件上
        System.setIn(in);
        //并将标准输出和标准错误重定向到另一个文件out上
        System.setOut(out);
        System.setErr(out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        out.close();
        System.setOut(console);
    }
}
